<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>hashcat-3.201: H:/TDDownload/Hashcat v3.20/hashcat-3.201/src/affinity.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">hashcat-3.201
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_06fe396e3e859736df6d43ad26baa72e.html">hashcat-3.201</a></li><li class="navelem"><a class="el" href="dir_9ce3dfc5d638c7f8b2c4ec0f6627771b.html">src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">affinity.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &quot;common.h&quot;</code><br />
<code>#include &quot;types.h&quot;</code><br />
<code>#include &quot;memory.h&quot;</code><br />
<code>#include &quot;event.h&quot;</code><br />
<code>#include &quot;affinity.h&quot;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for affinity.c:</div>
<div class="dyncontent">
<div class="center"><img src="affinity_8c__incl.gif" border="0" usemap="#_h_1_2_t_d_download_2_hashcat_01v3_820_2hashcat-3_8201_2src_2affinity_8c" alt=""/></div>
<map name="_h_1_2_t_d_download_2_hashcat_01v3_820_2hashcat-3_8201_2src_2affinity_8c" id="_h_1_2_t_d_download_2_hashcat_01v3_820_2hashcat-3_8201_2src_2affinity_8c">
<area shape="rect"  title=" " alt="" coords="161,5,324,61"/>
<area shape="rect"  title=" " alt="" coords="5,109,88,136"/>
<area shape="rect"  title=" " alt="" coords="113,109,178,136"/>
<area shape="rect"  title=" " alt="" coords="203,109,283,136"/>
<area shape="rect"  title=" " alt="" coords="307,109,370,136"/>
<area shape="rect"  title=" " alt="" coords="394,109,465,136"/>
</map>
</div>
</div>
<p><a href="affinity_8c_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a664f40010a232a9b7a6621128f0988d2"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="affinity_8c.html#a664f40010a232a9b7a6621128f0988d2">set_cpu_affinity</a> (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx)</td></tr>
<tr class="separator:a664f40010a232a9b7a6621128f0988d2"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Function Documentation</h2>
<a id="a664f40010a232a9b7a6621128f0988d2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a664f40010a232a9b7a6621128f0988d2">&#9670;&nbsp;</a></span>set_cpu_affinity()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int set_cpu_affinity </td>
          <td>(</td>
          <td class="paramtype">MAYBE_UNUSED hashcat_ctx_t *&#160;</td>
          <td class="paramname"><em>hashcat_ctx</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Author......: See docs/credits.txt License.....: MIT </p>

<p class="definition">Definition at line <a class="el" href="affinity_8c_source.html#l00048">48</a> of file <a class="el" href="affinity_8c_source.html">affinity.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;{</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;<span class="preprocessor">#if defined (__CYGWIN__)</span></div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;  <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;<span class="preprocessor">#else</span></div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;  <span class="keyword">const</span> user_options_t *user_options = hashcat_ctx-&gt;user_options;</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;  <span class="keywordflow">if</span> (user_options-&gt;cpu_affinity == NULL) <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;<span class="preprocessor">  #if defined (_WIN)</span></div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;  DWORD_PTR aff_mask = 0;</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;<span class="preprocessor">  #else</span></div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;  cpu_set_t cpuset;</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;  CPU_ZERO (&amp;cpuset);</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;<span class="preprocessor">  #endif</span></div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;  <span class="keywordtype">char</span> *devices = <a class="code" href="memory_8c.html#a03315d6f4ee82f54f7f4461a884dc32a">hcstrdup</a> (user_options-&gt;cpu_affinity);</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;  <span class="keywordtype">char</span> *saveptr = NULL;</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;  <span class="keywordtype">char</span> *next = strtok_r (devices, <span class="stringliteral">&quot;,&quot;</span>, &amp;saveptr);</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;  <span class="keywordflow">do</span></div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;  {</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    <span class="keywordtype">int</span> cpu_id = atoi (next);</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;    <span class="keywordflow">if</span> (cpu_id == 0)</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    {</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;<span class="preprocessor">      #if defined (_WIN)</span></div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;      aff_mask = 0;</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;<span class="preprocessor">      #else</span></div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;      CPU_ZERO (&amp;cpuset);</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;<span class="preprocessor">      #endif</span></div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;      <span class="keywordflow">break</span>;</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;    }</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;    <span class="keywordflow">if</span> (cpu_id &gt; 32)</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    {</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;      <a class="code" href="event_8c.html#ab419d8d7e9b12e78980ed9f17bdd5ed5">event_log_error</a> (hashcat_ctx, <span class="stringliteral">&quot;Invalid cpu_id %d specified&quot;</span>, cpu_id);</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;      <span class="keywordflow">return</span> (-1);</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;    }</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;<span class="preprocessor">    #if defined (_WIN)</span></div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;    aff_mask |= 1u &lt;&lt; (cpu_id - 1);</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;<span class="preprocessor">    #else</span></div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;    CPU_SET ((cpu_id - 1), &amp;cpuset);</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;<span class="preprocessor">    #endif</span></div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;  } <span class="keywordflow">while</span> ((next = strtok_r (NULL, <span class="stringliteral">&quot;,&quot;</span>, &amp;saveptr)) != NULL);</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;  <a class="code" href="memory_8c.html#ad8ba3dcf1734b1d2c8679600f0f0c3c9">hcfree</a> (devices);</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;<span class="preprocessor">  #if defined (_WIN)</span></div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;  SetProcessAffinityMask (GetCurrentProcess (), aff_mask);</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;  <span class="keywordflow">if</span> (SetThreadAffinityMask (GetCurrentThread (), aff_mask) == 0)</div><div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;  {</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;    <a class="code" href="event_8c.html#ab419d8d7e9b12e78980ed9f17bdd5ed5">event_log_error</a> (hashcat_ctx, <span class="stringliteral">&quot;%s&quot;</span>, <span class="stringliteral">&quot;SetThreadAffinityMask()&quot;</span>);</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;    <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;  }</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;<span class="preprocessor">  #else</span></div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;  pthread_t thread = pthread_self ();</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;  <span class="keywordflow">if</span> (pthread_setaffinity_np (thread, <span class="keyword">sizeof</span> (cpu_set_t), &amp;cpuset) == -1)</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;  {</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;    <a class="code" href="event_8c.html#ab419d8d7e9b12e78980ed9f17bdd5ed5">event_log_error</a> (hashcat_ctx, <span class="stringliteral">&quot;%s&quot;</span>, <span class="stringliteral">&quot;pthread_setaffinity_np()&quot;</span>);</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;    <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;  }</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;<span class="preprocessor">  #endif</span></div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;  <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;}</div><div class="ttc" id="memory_8c_html_ad8ba3dcf1734b1d2c8679600f0f0c3c9"><div class="ttname"><a href="memory_8c.html#ad8ba3dcf1734b1d2c8679600f0f0c3c9">hcfree</a></div><div class="ttdeci">void hcfree(void *ptr)</div><div class="ttdef"><b>Definition:</b> <a href="memory_8c_source.html#l00071">memory.c:71</a></div></div>
<div class="ttc" id="event_8c_html_ab419d8d7e9b12e78980ed9f17bdd5ed5"><div class="ttname"><a href="event_8c.html#ab419d8d7e9b12e78980ed9f17bdd5ed5">event_log_error</a></div><div class="ttdeci">size_t event_log_error(hashcat_ctx_t *hashcat_ctx, const char *fmt,...)</div><div class="ttdef"><b>Definition:</b> <a href="event_8c_source.html#l00168">event.c:168</a></div></div>
<div class="ttc" id="memory_8c_html_a03315d6f4ee82f54f7f4461a884dc32a"><div class="ttname"><a href="memory_8c.html#a03315d6f4ee82f54f7f4461a884dc32a">hcstrdup</a></div><div class="ttdeci">char * hcstrdup(const char *s)</div><div class="ttdef"><b>Definition:</b> <a href="memory_8c_source.html#l00056">memory.c:56</a></div></div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="event_8c_source.html#l00168">event_log_error()</a>, <a class="el" href="memory_8c_source.html#l00071">hcfree()</a>, and <a class="el" href="memory_8c_source.html#l00056">hcstrdup()</a>.</p>

<p class="reference">Referenced by <a class="el" href="hashcat_8c_source.html#l00833">hashcat_session_init()</a>.</p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="affinity_8c_a664f40010a232a9b7a6621128f0988d2_cgraph.gif" border="0" usemap="#affinity_8c_a664f40010a232a9b7a6621128f0988d2_cgraph" alt=""/></div>
<map name="affinity_8c_a664f40010a232a9b7a6621128f0988d2_cgraph" id="affinity_8c_a664f40010a232a9b7a6621128f0988d2_cgraph">
<area shape="rect"  title=" " alt="" coords="5,81,117,108"/>
<area shape="rect"  href="event_8c.html#ab419d8d7e9b12e78980ed9f17bdd5ed5" title=" " alt="" coords="165,31,275,57"/>
<area shape="rect"  href="memory_8c.html#ad8ba3dcf1734b1d2c8679600f0f0c3c9" title=" " alt="" coords="191,81,249,108"/>
<area shape="rect"  href="memory_8c.html#a03315d6f4ee82f54f7f4461a884dc32a" title=" " alt="" coords="184,132,256,159"/>
<area shape="rect"  href="event_8c.html#ad5a30ac9dc4301540e19643500eb78e4" title=" " alt="" coords="324,5,400,32"/>
<area shape="rect"  href="event_8c.html#a6221c6caa1d2069ad1c3103f0b013ef7" title=" " alt="" coords="323,56,401,83"/>
<area shape="rect"  href="memory_8c.html#aac788cecd4f6c2a1524456f4a5db7cdc" title=" " alt="" coords="325,132,399,159"/>
</map>
</div>
<div class="dynheader">
Here is the caller graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="affinity_8c_a664f40010a232a9b7a6621128f0988d2_icgraph.gif" border="0" usemap="#affinity_8c_a664f40010a232a9b7a6621128f0988d2_icgraph" alt=""/></div>
<map name="affinity_8c_a664f40010a232a9b7a6621128f0988d2_icgraph" id="affinity_8c_a664f40010a232a9b7a6621128f0988d2_icgraph">
<area shape="rect"  title=" " alt="" coords="296,5,408,32"/>
<area shape="rect"  href="hashcat_8c.html#a9f3f1b757bdc2a874b4bb0dc657bde1d" title=" " alt="" coords="104,5,248,32"/>
<area shape="rect"  href="main_8c.html#a3c04138a5bfe5d72780bb7e82a18e627" title=" " alt="" coords="5,5,56,32"/>
</map>
</div>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.15
</small></address>
</body>
</html>
